<template>
  <el-row type="flex" align="middle" style="height: 40px;width:100%">
    <el-col :span="20">
      <i v-if="isRoot" class="el-icon-platform-eleme" />
      <span>{{ nodeData.name }}</span>
    </el-col>
    <el-col :span="4">
      <el-row type="flex" justify="end">
        <el-col>{{ nodeData.manager }}</el-col>
        <el-col>
          <el-dropdown>
            <span class="el-dropdown-link" @click.stop>
              操作<i class="el-icon-arrow-down el-icon--right" />
            </span>
            <template #dropdown>
              <el-dropdown-menu>
                <el-dropdown-item @click.native="addDept">添加子部门</el-dropdown-item>
                <el-dropdown-item v-if="!isRoot" @click.native="editDept">修改部门</el-dropdown-item>
                <el-dropdown-item v-if="!isRoot" @click.native="del">删除部门</el-dropdown-item>
              </el-dropdown-menu>
            </template>

          </el-dropdown>
        </el-col>
      </el-row>
    </el-col>
  </el-row>
</template>

<script>
import { delDepart } from '@/api/dept'
export default {
  name: 'TreeTools',
  props: {
    nodeData: {
      type: Object,
      required: true
    },
    isRoot: {
      type: Boolean,
      default: false
    }

  },
  methods: {
    async del() {
      try {
        await this.$confirm('你确定要删除此部门吗?', '温馨提示', { type: 'warning' })
      } catch {
        return
      }
      await delDepart(this.nodeData.id)
      this.$message.success('删除成功')
      this.$emit('getDeptList')
    },
    addDept() {
      this.$emit('addDepart', this.nodeData.id)
    },
    // 点击编辑修改
    editDept() {
      this.$emit('editDept', this.nodeData.id)
    }
  }
}
</script>

<style>

</style>
